<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<form id="form-cus-upd" class="m-3">

  <div class="form-group">
    <label for="upd-cus_id">客户编号</label>
    <input type="text" class="form-control" id="upd-cus_id" name="cus_id" value="${cus.cus_id }" readonly="readonly" >
  </div>
  <div class="form-group">
    <label for="upd-cus_name">客户名称</label>
    <input type="text" class="form-control" id="upd-cus_name" name="cus_name" value="${cus.cus_name }" >
  </div>
  <div class="form-group">
    <label for="upd-cus_remark">客户备注</label>
    <input type="text" class="form-control" id="upd-cus_remark" name="cus_remark" value="${cus.cus_remark }" >
  </div>
  
 
  <button type="button" id="bn-cus-upd-do"  class="btn btn-primary">保存</button>
</form>

<script>

//修改弹窗保存按钮事件
$('#bn-cus-upd-do').click(function(){
	
	//确认是否保存
	layer.confirm('你确实要修改该客户信息吗？', {icon: 3, title:'警告'}, function(index){
		//参数index是本确认框的编号
		 
		let loadLayerIdx = layer.load();//显示加载层
		
		let arr = $('#form-cus-upd').serializeArray();
		let data = {};	
		for(let ele of arr){
			data[ele.name]=ele.value;
		}
		let jsonStr = JSON.stringify(data);//将对象data转换成json格式的字符串
		
		
		
		$.ajax({
			url:'customer',
			method:'put',
			contentType:'application/json',
			data:jsonStr,
			dataType:'json'
		})
		.done((result)=>{
			
			layer.close(loadLayerIdx);
			
			if(result.success){
				reloadData();//重载数据
				layer.msg(
						result.message, 
						{
						  icon: 1,
						  time: 1000 //1秒关闭（如果不配置，默认是3秒）
						}
				); 
				layer.close(layerIdx);//关闭窗口
			}else{
				layer.msg(result.message, {icon: 6}); 
			}
		})
		.fail((xhr)=>{
			
			layer.close(loadLayerIdx);
			layer.msg('服务器错误！', {icon: 6}); 
			
		});
		  
		  
		layer.close(index);//关闭确认框
		
	});
	
	
	
});



</script>